#include<stack>
using namespace std;


//最小栈
class MinStack {
public:
    MinStack() 
    {
        //min_stack.push(INT_MAX);//防止删空了 top访问空指针报错
    }
    
    void push(int val) 
    {
        if(min_stack.empty())
        {
            min_stack.push(val);
        }
        else if(min_stack.top()<=val)
        {
            min_stack.push(min_stack.top());
        }
        else
        {
            min_stack.push(val);
        }
        data_stack.push(val);
    }
    
    void pop() 
    {
        data_stack.pop();
        min_stack.pop();
    }
    
    int top() 
    {
        return data_stack.top();
    }
    
    int getMin() 
    {
        return min_stack.top();
    }
private:
    stack<int> data_stack;
    stack<int> min_stack;
};

//栈的压入弹出序列
class Solution {
public:
    bool IsPopOrder(vector<int> pushV,vector<int> popV) 
    {
        int n = pushV.size();
        stack<int> s;
        //遍历入栈的下标
        int j = 0;
        for(int i = 0; i < n; i++)
        {
            while(j < n && (s.empty() || s.top() != popV[i]))
            {
                s.push(pushV[j]);
                j++;
            }
            //栈顶等于出栈数组
            if(s.top() == popV[i])
                s.pop();
            else
                return false;
        }
        return true;
    }
};
